package PhienBanNIO;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class Read {
	public static void main (String [] args){
		try {
			FileInputStream file = new FileInputStream("D:\\a.txt");
			FileChannel inChannel = file.getChannel();
			ByteBuffer buffer = ByteBuffer.allocate(1024);
			
				while(inChannel.read(buffer)>0){
					 buffer.flip();
					 for(int i=0;i<buffer.limit();i++){
						 System.out.print((char) buffer.get());
					 }
					 
					 buffer.clear();	
				}
			
				inChannel.close();
				file.close();
				
		} catch (FileNotFoundException e) {
			System.out.println("Khong co file");
			}
		catch(IOException e){
			
		}
		
		
	}
}
